//package com.fenghuajueli.module_home.fragment
//
//import android.graphics.Color
//import android.graphics.Rect
//import android.os.Bundle
//import androidx.fragment.app.Fragment
//import android.view.LayoutInflater
//import android.view.View
//import android.view.ViewGroup
//import androidx.recyclerview.widget.LinearLayoutManager
//import androidx.recyclerview.widget.RecyclerView
//import com.alibaba.android.arouter.facade.annotation.Route
//import com.blankj.utilcode.util.SizeUtils
//import com.fenghuajueli.libbasecoreui.baseswitch.PublicFunction
//import com.fenghuajueli.libbasecoreui.recycler.hide
//import com.fenghuajueli.libbasecoreui.recycler.show
//import com.fenghuajueli.libbasecoreui.utils.JumpActivityUtils
//import com.fenghuajueli.libbasecoreui.utils.TimeUtils
//import com.fenghuajueli.libbasecoreui.viewmodel.BaseViewModel2
//import com.fenghuajueli.libbasecoreui.viewmodel.BaseViewModelFragment2
//import com.fenghuajueli.module_home.activity.ClockinActivity
//import com.fenghuajueli.module_home.adapter.ClockinPlanAdapter
//import com.fenghuajueli.module_home.db.ClockinPlanEntity
//import com.fenghuajueli.module_home.model.ClockinModel
//import com.fenghuajueli.module_route.HomeModuleRoute
//import com.module.shici.R
//import com.module.shici.databinding.ModuleShiciFragmentClockinBinding
//
//class ClockinFragment : BaseViewModelFragment2<ClockinModel, ModuleShiciFragmentClockinBinding>() {
//
//    private val clockinPlanAdapter by lazy {
//        ClockinPlanAdapter(null) { clockinPlanEntity, type ->
//            if (type == "modify") {
//                ClockinActivity.start(requireContext(), clockinPlanEntity)
//            } else if (type == "status") {
//                clockinPlanEntity.isFinished = !clockinPlanEntity.isFinished
//                model.modifyClockinPlan1(requireContext(), clockinPlanEntity)
//            }
//        }
//    }
//    private var isTypeFinished = false
//
//    override fun createViewModel(): ClockinModel {
//        return ClockinModel()
//    }
//
//    override fun createViewBinding(): ModuleShiciFragmentClockinBinding {
//        return ModuleShiciFragmentClockinBinding.inflate(layoutInflater)
//    }
//
//    override fun initView(containerView: View?) {
//        with(binding) {
//            rvClockinList.apply {
//                layoutManager =
//                    LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
//                if (itemDecorationCount == 0) {
//                    addItemDecoration(object : RecyclerView.ItemDecoration() {
//                        override fun getItemOffsets(
//                            outRect: Rect,
//                            view: View,
//                            parent: RecyclerView,
//                            state: RecyclerView.State
//                        ) {
//                            super.getItemOffsets(outRect, view, parent, state)
//                            outRect.bottom = SizeUtils.dp2px(20f)
//
//                        }
//                    })
//                }
//                addOnScrollListener(object : RecyclerView.OnScrollListener() {
//                    override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
//                        super.onScrollStateChanged(recyclerView, newState)
//                        if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
//                            ivAdd.hide()
//                        } else {
//                            ivAdd.show()
//                        }
//                    }
//                })
//                adapter = clockinPlanAdapter
//            }
//
//            loadClockinPlanData()
//            bindListener()
//        }
//    }
//
//    private fun ModuleShiciFragmentClockinBinding.bindListener() {
//        btnStudyList.setOnClickListener(listener)
//        btnCompleteStudyList.setOnClickListener(listener)
//        ivAdd.setOnClickListener(listener)
//    }
//
//    override fun initData() {
//
//    }
//
//    private val listener = View.OnClickListener {
//        when (it.id) {
//            R.id.btn_study_list -> {
//                binding.changeClockinPlanStatus(false)
//                loadClockinPlanData()
//            }
//            R.id.btn_complete_study_list -> {
//                binding.changeClockinPlanStatus(true)
//                loadClockinPlanData()
//            }
//            R.id.iv_add -> if (PublicFunction.checkCanUsedByPosition(1, true)) {
//                ClockinActivity.start(requireContext(), null)
//            }
//        }
//    }
//
//    private fun ModuleShiciFragmentClockinBinding.changeClockinPlanStatus(isFinished: Boolean) {
//        isTypeFinished = isFinished
//        if (isTypeFinished) {
//            btnCompleteStudyList.setBackgroundResource(R.mipmap.module_shici_icon_clockin_topbar_bg_sel)
//            btnStudyList.setBackgroundResource(android.R.color.transparent)
//            btnCompleteStudyList.setTextColor(Color.parseColor("#353B42"))
//            btnStudyList.setTextColor(Color.parseColor("#B3FFFFFF"))
//        } else {
//            btnStudyList.setBackgroundResource(R.mipmap.module_shici_icon_clockin_topbar_bg_sel)
//            btnCompleteStudyList.setBackgroundResource(android.R.color.transparent)
//            btnStudyList.setTextColor(Color.parseColor("#353B42"))
//            btnCompleteStudyList.setTextColor(Color.parseColor("#B3FFFFFF"))
//        }
//    }
//
//
//    private fun loadClockinPlanData() {
//        model.loadAllClockinPlan(requireContext())
//            .observe(viewLifecycleOwner) { clockinPlanEntityList ->
//                if (clockinPlanEntityList.isNullOrEmpty()) {
//                    return@observe
//                }
//                if (isTypeFinished) {
//                    clockinPlanAdapter.setList(clockinPlanEntityList.filter {
////                        TimeUtils.getLongTime(
////                            it.remindTime
////                        ) < System.currentTimeMillis()
//                        it.isFinished
//                    })
//                } else {
//                    clockinPlanAdapter.setList(clockinPlanEntityList.filterNot {
////                        TimeUtils.getLongTime(
////                            it.remindTime
////                        ) < System.currentTimeMillis()
//                        it.isFinished
//                    })
//                }
//            }
//    }
//
//}